package com.TLLT.QADMobileItemEnquiry2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class ScanFragment  extends Fragment {
	
	Button btScan;
	public TextView tvResult;
	
	public static ScanFragment newInstance(int index) {
		ScanFragment f = new ScanFragment();

        // Supply index input as an argument.
        Bundle args = new Bundle();
        args.putInt("index", index);
        f.setArguments(args);

        return f;
    }

    public int getShownIndex() {
        return getArguments().getInt("index", 0);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }
        View scanLayout = inflater.inflate(R.layout.scan_tab, null);
        getScanView(scanLayout);
        return scanLayout;
    }
    
    public void getScanView(View v) {
		tvResult=(TextView)v.findViewById(R.id.textViewItem);
		Button btScan = (Button) v.findViewById(R.id.buttonScan);
		btScan.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				lounchScaning();
			}
		});
	}
    
    void lounchScaning(){
		Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_FORMATS","EAN_8,UPC_A,UPC_E,EAN_13,CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR");
		getActivity().startActivityForResult(intent, 0);
	}
    
}
